<template>
	<view class="content">
		<!-- 未登录 -->
		<view class="head" @click="toLogin" v-if="!haveLogin">
			<image src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-8568e76c-23c5-4d05-bd27-7ff891e61576/461db27c-628f-4548-895a-0e4593de93a9.png" mode="scaleToFill"></image>
			<view class="text">
				登录/注册
			</view>
			<image id="img" src="/static/img/my_slices/Component1@2x.png" mode="scaleToFill"></image>
		</view>
		<!-- 已登录 -->
		<view class="head" v-if="haveLogin">
			<image :src="avatar" mode="scaleToFill" v-if="avatar"></image>
			<image src="/static/img/headimg.png" mode="scaleToFill" v-if="!avatar || avatar==null"></image>
			<view class="text">
				<span>{{name}}</span>
				<span style="display:block;font-size: 12px;">{{schoolName}}</span>
			</view>
			
		</view>
		<!-- 完善简历 -->
		<view class="resume" v-show="haveLogin" @click="toFinishResume">
			<image src="/static/img/my_slices/Group441@2x.png" mode="scaleToFill"></image>
			<view class="text">
				<span>完善个人简历</span>
				<span v-if="resumePercent!=100">我的简历{{resumePercent}}%</span>
			</view>
			<button class="button">立即完善</button>
		</view>
		<!-- 职位情况 -->
		<view class="data" @click="toJobProgress">
			<view class="dataBox">
				<span>{{personalData.all}}</span>
				<span>全部</span>
			</view>
			<view class="dataBox">
				<span>{{personalData.registered}}</span>
				<span>已报名</span>
			</view>
			<view class="dataBox">
				<span>{{personalData.admitted}}</span>
				<span>已录取</span>
			</view>
			<view class="dataBox">
				<span>{{personalData.finish}}</span>
				<span>已完成</span>
			</view>
		</view>
		<!-- 选项 -->
		<view class="selection">
			<view class="selectionBox" @click="toAssets">
				<view class="left">
					<image src="/static/img/my_slices/Group493@2x.png" mode="scaleToFill"></image>
					<span>我的资产</span>
					<span>(红包余额¥{{money}})</span>
				</view>
				<view class="right">
					<image src="/static/img/my_slices/Frame222@2x.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="selectionBox" @click="toMyColltion">
				<view class="left">
					<image src="/static/img/my_slices/Group269@2x.png" mode="scaleToFill"></image>
					<span>我的收藏</span>
				</view>
				<view class="right">
					<image src="/static/img/my_slices/Frame222@2x.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="selectionBox" @click="toHelp">
				<view class="left">
					<image src="/static/img/my_slices/help@2x.png" mode="scaleToFill"></image>
					<span>帮助中心</span>
				</view>
				<view class="right">
					<image src="/static/img/my_slices/Frame222@2x.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="selectionBox">
				<view class="left">
					<image src="/static/img/my_slices/Group305@2x.png" mode="scaleToFill"></image>
					<span>联系客服</span>
				</view>
				<view class="right">
					<image src="/static/img/my_slices/Frame222@2x.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="selectionBox" @click="toChangeRole">
				<view class="left">
					<image src="/static/img/my_slices/Group306@2x.png" mode="scaleToFill"></image>
					<span>{{role}}</span>
				</view>
				<view class="right">
					<span>切换版本</span>
					<image src="/static/img/my_slices/Frame222@2x.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="selectionBox" @click="toSetting">
				<view class="left">
					<image src="/static/img/my_slices/setting@2x.png" mode="scaleToFill"></image>
					<span>设置</span>
				</view>
				<view class="right">
					<image src="/static/img/my_slices/Frame222@2x.png" mode="scaleToFill"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				haveLogin:false,		//是否登录？
				avatar:'',				//头像
				name:'',				//昵称姓名
				resumePercent:0,		//简历完成度
				schoolName:'',			//学校名称
				personalData:{
					all:0,
					registered:0,
					admitted:0,
					finish:0,
				},
				role:'求职者',			//角色身份
				money:'',				//红包余额
			}
		},
		onLoad() {
			
		},
		onShow() {
			// let now=Number(new Date())
			// console.log(now);
			let source=NaN
			//#ifdef H5
			source=1
			//#endif
			//#ifdef MP-WEIXIN
			source=2
			//#endif
			//#ifdef MP-ALIPAY
			source=3
			//#endif
			this.$store.dispatch('initDic').then(()=>{
				this.$http.request({
					url:'/user/mine',
					data:{
						source:source
					}
				}).then((result)=>{
					let res=result.data
					console.log('响应结果',res);
					if(res.code==200){
						this.avatar=res.data.avatar
						this.name=res.data.name
						this.schoolName=res.data.schName
						this.resumePercent=res.data.resumePerfection
						this.personalData.all=res.data.totalEnroll
						this.personalData.registered=res.data.enrolledNum
						this.personalData.admitted=res.data.recruitedNum
						this.personalData.finish=res.data.completedNum
						this.money=res.data.wageBalance
					} else if (res.code==203) {
						this.haveLogin=false
						uni.removeStorageSync('loginInfo')
						uni.showToast({
							title: '登陆已过期，请重新登录',
							icon: 'none'
						})
					}
				})
			})
			
			
			if(uni.getStorageSync('token')){
				this.haveLogin=true
				let loginInfo=uni.getStorageSync('loginInfo')
			}
			
		},
		methods: {
			toLogin(){
				//前往登录页
				uni.navigateTo({
					url:'/subpageB/common/login/login1'
				})
			},
			toFinishResume(){
				// 前往完善简历
				uni.navigateTo({
					url:'/subpageA/my/finishResume/finishResume1'
				})
			},
			toJobProgress(){
				//前往职位进展
				uni.navigateTo({
					url:'/subpageA/my/jobProgress/jobProgress'
				})
			},
			toAssets(){
				//前往我的资产
				uni.navigateTo({
					url:'/subpageA/my/assets/assets'
				})
			},
			toMyColltion(){
				//前往我的收藏
				uni.navigateTo({
					url:'/subpageA/my/myCollection/myCollection'
				})
			},
			toHelp(){
				//前往帮助中心
				uni.navigateTo({
					url:'/subpageA/my/help/help'
				})
			},
			toChangeRole(){
				//前往切换版本
				uni.navigateTo({
					url:'/subpageA/my/changeRole/changeRole'
				})
			},
			toSetting(){
				// 前往设置
				uni.navigateTo({
					url:'/subpageA/my/setting/setting'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 100%;
		height: 100vh;
		background-image: url('https://vkceyugu.cdn.bspapp.com/VKCEYUGU-8568e76c-23c5-4d05-bd27-7ff891e61576/278d63e0-058f-4509-8202-b9922793a525.png');
		background-color: #FFFFFF;
		background-repeat: no-repeat;
		background-size: 100%;
		padding: 1px 0;
		
		.head{
			display: flex;
			align-items: center;
			height: 128rpx;
			margin: 32rpx;
			margin-top: 120rpx;
			
			image:nth-of-type(1){
				width: 128rpx;
				height: 128rpx;
				border-radius:64rpx
			}
			#img{
				width:16rpx;
				height: 30rpx;
			}
			.text{
				display: inline-block;
				margin: 0 32rpx;
				font-size: 20px;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				
				
			}
			
		}
		
		.resume{
			width: 686rpx;
			height: 126rpx;
			margin: 32rpx;
			background: #021A31;
			border-radius: 8px 8px 8px 8px;
			image{
				margin-left: 32rpx ;
				margin-top: 30rpx;
				width: 68rpx;
				height: 68rpx;
				
			}
			.text{
				display: inline-block;
				margin-left: 12rpx;
				span:nth-of-type(1){
					display: inline-block;
					
					font-size: 16px;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}
				span:nth-of-type(2){
					display: block;
					font-size: 12px;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #08C8BD;
				}
			}
			
			.button{
				display: flex;
				justify-content: center;
				align-items: center;
				float: right;
				margin-right: 32rpx;
				transform: translate(0,40rpx);
				width: 160rpx;
				height: 50rpx;
				background: #08C8BD;
				border-radius: 4px 4px 4px 4px;
				font-size: 12px;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}
			
		}
		
		.data{
			display: flex;
			margin: 0 32rpx;
			width: 686rpx;
			height: 160rpx;
			background: #FFFFFF;
			border-radius: 8px 8px 8px 8px;
			
			.dataBox{
				flex:1;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				
				span:nth-of-type(1){
					font-size: 20px;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #001A18;
				}
				span:nth-of-type(2){
					font-size: 14px;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #505E5C;
				}
			}
		}
	
		.selection{
			width: 622rpx;
			margin: 32rpx;
			padding: 32rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			.selectionBox{
				width: 100%;
				margin-bottom: 40rpx;
				&:nth-last-of-type(1){
					margin-bottom: 0;
				}
				display: flex;
				justify-content: space-between;
				
				.left{
					display: flex;
					align-items: center;
					image{
						width: 48rpx;
						height: 48rpx;
					}
					>span:nth-of-type(1){
						display: inline-block;
						margin-left: 20rpx;
						margin-right: 10rpx;
						font-size: 28rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #001A18;
					}
					>span:nth-of-type(2){
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #99A3A3;
					}
				}
				.right{
					display: flex;
					align-items: center;
					>span{
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #505E5C;
						margin-right: 10rpx;
					}
					>image{
						width: 16rpx;
						height: 30rpx;
					}
				}
				
			}
			
		}
	
	}
</style>
